package com.game.repository;

import java.time.LocalDateTime;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.game.entity.UserSession;

public interface UserSessionRepository extends JpaRepository<UserSession, Long> {
    Optional<UserSession> findByToken(String token);
    
    @Modifying
    @Query("DELETE FROM UserSession us WHERE us.token = ?1")
    void deleteByToken(String token);
    
    @Modifying
    @Query("DELETE FROM UserSession us WHERE us.expireTime < ?1")
    void deleteExpiredSessions(LocalDateTime now);
} 